#include "sqliteDataProvider.h"
#include "id3TagParser.h"
#include "exifTagParser.h"

int main(int argc, char **argv)
{
	int i;
	int mode = 0;
	char query[512] = {'\0'};
	sqlite3 *sqliteDB;
	id3filedata thisFile;
	exiffiledata exifFile;
	arraycontainer results;
	initDatabase("test.db",&sqliteDB);

	for ( i = 1; i < argc; i++)
	{
		if (mode == 0)
		{
			if (argv[i][strlen(argv[i]) - 1] == '3')
				mode = 1;
			else if (argv[i][strlen(argv[i]) - 1] == 'g')
				mode = 2;
			else
				mode = 3;
		}
		if (mode == 2)
		{
			initEXIFStruct(&exifFile);
			getEXIFInfo(argv[i],&exifFile);
			printEXIFData(&exifFile);
			insertjpgInfo(&sqliteDB,&exifFile);
			freeEXIFStruct(&exifFile);
		}
		else if (mode == 1)
		{
			initid3Struct(&thisFile);
			getInfo(argv[i],&thisFile);
			printData(&thisFile);
			insertmp3Info(&sqliteDB,&thisFile);
			freeid3Struct(&thisFile);
		}
		else
		{


		}
	}
	strcpy(query,"Select distinct songAlbum from mp3Info where songArtist=\'Metallica\'");
	getData(&sqliteDB,query,&results);
	printf("\nAlbums - ");
	for (i = 0; i < results.numelements; i++)
	{
		printf("%d. %s\n",i,results.dataarray[i]);
	}
	printf("\n");
	i = 0;
	strcpy(query,"UPDATE OR IGNORE mp3Info SET songArtist = \'Mentallica\' where songArtist=\'Metallica\'");
	i = sqliteExecute(sqliteDB,query,0,0);
	printf("\n%d rows affected by update.",i);
	i = 0;
	strcpy(query,"DELETE from mp3Info where songArtist=\'Mentallica\'");
	i = sqliteExecute(sqliteDB,query,0,0);
	printf("\n%d rows affected by delete.",i);
	deInit(sqliteDB);
	return 0;
}
